package com.flowable.listener;

import com.flowable.mapper.LeaveMapper;
import com.flowable.pojo.Leave;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 长沙先飞信息科技有限公司<br>
 * Created with IntelliJ IDEA.<br>
 * Date:2024/7/8<br>
 * Time:13:50<br>
 * 功能描述：<br>
 *
 * @author huang hou chun
 * @since JDK 1.8 <br>
 * Copyright (c) 2023 www.csxfrj.com System Incorporated All Rights Reserved.
 */
@Component
public class ApprovedTaskListener implements TaskListener {

    @Resource
    private LeaveMapper leaveMapper;

    @Override
    public void notify(DelegateTask delegateTask) {
        String processInstanceId = delegateTask.getProcessInstanceId();
        Leave leave = new Leave();
        leave.setProcessInstanceId(processInstanceId);
        leave.setLeaderApproved(delegateTask.getVariable("leaderApproved", Boolean.class));
        leaveMapper.updateByProcessInstanceId(leave);
    }
}
